package edu.bu.bga;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;
import edu.bu.bga.generator.DatabaseRuleGenerator;
import edu.bu.bga.generator.RuleGenerator;

public class GetRuleActivity extends Activity {

	private Button backButton;
	private Button generateRuleButton;
	private TextSwitcher textSwitcher;

	private RuleGenerator ruleGenerator;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rulelayout);

		backButton = (Button) this.findViewById(R.id.backbutton);
		backButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		// ruleGenerator = new RandomRuleGenerator();
		ruleGenerator = new DatabaseRuleGenerator(getApplicationContext());

		textSwitcher = (TextSwitcher) this.findViewById(R.id.textSwitcher1);
		textSwitcher.setFactory(new ViewFactory() {

			@Override
			public View makeView() {
				TextView t = new TextView(getBaseContext());
				t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
				t.setTextSize(36);
				return t;

			}
		});

		generateRuleButton = (Button) this
				.findViewById(R.id.generaterulebutton);
		generateRuleButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				String newRule = ruleGenerator.generateRule().getRuleText();
				textSwitcher.setText(newRule);
			}
		});

	}

}
